<?php

abstract class Field {
    protected $name;
    protected $type;
    protected $caption;
    protected $value;
    protected $isRequired;
    protected $parameters;
    protected $help;
    
    public $css_class;
    public $css_style;
    
    function __construct($name, $type, $caption, $isRequired = false, $value = "", $parameters = "", $help = "") {
        $this->name = $this->encodestring($name);
        $this->type = $type;
        $this->caption = $caption;
        if (!get_magic_quotes_gpc()) {
            $this->value = mysql_escape_string($this->value);
        }
        $this->isRequired = $isRequired;
        $this->parameters = $parameters;
        $this->help = $help;

    }
    /**
     * Метод для проверки корректности заполнения поля 
     */
    abstract function check();
    /**
     * Метод возвращающий название поля и самого тега
     * элемента управления 
     */
    abstract function getHtml();

    /**
     * 
     * @param type $name 
     */
    public function __get($key) {
        if (isset($this->$key))
            return $this->$key;
        else {
            throw new ExceptionMember($key, 'Член ' . __CLASS__ . '::' . $key . ' не существует');
        }
    }

    /**
     * Перевод текста с русского языка в транслит
     * @param type $st
     * @return type 
     */
    protected function encodestring($st) {
        // Сначала заменяем "односимвольные" фонемы.
        $st = strtr($st, "абвгдеёзийклмнопрстуфхъыэ_", "abvgdeeziyklmnoprstufh'iei");
        $st = strtr($st, "АБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЭ_", "ABVGDEEZIYKLMNOPRSTUFH'IEI");
        // Затем - "многосимвольные".
        $st = strtr($st, array(
            "ж" => "zh", "ц" => "ts", "ч" => "ch", "ш" => "sh",
            "щ" => "shch", "ь" => "", "ю" => "yu", "я" => "ya",
            "Ж" => "ZH", "Ц" => "TS", "Ч" => "CH", "Ш" => "SH",
            "Щ" => "SHCH", "Ь" => "", "Ю" => "YU", "Я" => "YA",
            "ї" => "i", "Ї" => "Yi", "є" => "ie", "Є" => "Ye"
                )
        );
        return $st;
    }
    

}
?>
